package com.agileboot.medicine.controller.algorithm;

import org.apache.commons.text.similarity.CosineSimilarity;
import org.apache.commons.text.similarity.LevenshteinDistance;

/**
 * 文本相似度计算
 */
public class TextSimilarityCalculator {

//    public static double calculateCosineSimilarity(String text1, String text2) {
//        CosineSimilarity cosineSimilarity = new CosineSimilarity();
//        return cosineSimilarity.cosineSimilarity(text1, text2);
//    }

    public static double calculateLevenshteinDistance(String text1, String text2) {
        LevenshteinDistance levenshteinDistance = new LevenshteinDistance();
        return 1 - (double) levenshteinDistance.apply(text1, text2) / Math.max(text1.length(), text2.length());
    }
}
